package org.pr.springboot_autodev.controller;

import com.alibaba.fastjson2.JSONPObject;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.annotations.Operation;
import org.pr.springboot_autodev.annatation.SysLog;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.w3c.dom.DOMException;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
import org.w3c.dom.ranges.Range;
import org.w3c.dom.ranges.RangeException;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @ProjectName: SpringBoot_AutoDev
 * @Package: org.pr.springboot_autodev.controller
 * @ClassName: HelloController
 * @Author: LXC
 * @Description: 消息控制器
 * @Date: 2025/8/24 13:30
 */
@RestController
@RequestMapping("/api/hello")
public class HelloController {

    @Operation(summary = "Hello接口", description = "返回固定的Hello字符串")
    @GetMapping("/api/hello")
    public String hello() {
        return "Hello, Swagger + DevTools![已修改2]";
    }

    @Operation(summary = "获取消息", description = "获取实时消息串")
    @GetMapping("/api/getMessage")
    public String getMessage() {
        return "Hello, Swagger + DevTools![已修改3]";
    }

    List<String> list = Arrays.asList("banana", "apple", "orange");

    @SysLog("整理集合")
    @Operation(summary = "整理集合", description = "整理集合 ")
    @ResponseBody
    @GetMapping("/api/sortCollection")
    public List<String> sortCollection() {
        List<String> sorted = list.stream()
                .sorted() // 默认自然排序
                .toList();

        System.out.println(sorted); // [apple, banana, orange]

        List<String> sortedByLength = list.stream()
                .sorted(Comparator.comparingInt(String::length))
                .toList();

        System.out.println(sortedByLength);
        return sortedByLength;// [apple, orange, banana]
    }

    @ResponseBody
    @SysLog("整理集合2")
    @Operation(summary = "整理集合2", description = "整理集合2")
    @GetMapping("/sortCollection2")
    public List<String> sortCollection2() {
        System.out.println(list.stream().sorted().toList());
        return list.stream()
                .sorted(Comparator.comparingInt(String::length))
                .toList();
    }
}
